package com.ptu.mapper;

import com.github.pagehelper.Page;
import com.ptu.entity.Product;
import com.ptu.entity.ProductStatusDTO;
import com.ptu.entity.User;
import com.ptu.vo.HotVO;
import com.ptu.vo.ProductFlVO;
import com.ptu.vo.ProductVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface ProductMapper {

    @Select("select * from product where category_id = #{categoryId}")
    List<ProductFlVO> getCategory(int categoryId);

    @Select("select * from product where id = #{id}")
    ProductVO getDetailById(int id);

    @Select("select * from product where name like concat('%', #{name}, '%') and category_id = #{categoryId}")
    List<ProductVO> getProductByName(String name, Integer categoryId);

    @Update("update product set is_favorite = #{isFavorite} where id = #{id}")
    void collect(int id, int isFavorite);

//    @Select("select * from product where is_favorite = 1 and user_id = #{id}")
//    List<ProductVO> getFavoriteList(int id);

    @Select("select * from product where id = #{id}")
    Product selectById(Long productId);

    @Update("update product set stock = #{stock} where id = #{id}")
    void updateById(Product product);

    Page<Product> pageQuery(String name, Integer categoryId);

    void adminUpdateById(Product product);

    void insert(Product product);

    @Delete("delete from product where id = #{id}")
    void deleteById(Long id);

    @Update("update product set status = #{i} where id = #{id}")
    void startOrStop(Long id, int i);

    @Select("select * from product where id = #{id}")
    Product adminSelectById(Long id);

    List<HotVO> getHotListByCategory(String type, Integer categoryId);

    List<HotVO> getUserHotListByCategory(@Param("type") String type,
                                         @Param("categoryId") Integer categoryId,
                                         @Param("userId") int userId);
}
